<template>
	<view class="message">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				警告中心<text>(仅警告已安装的设备)</text>
				<view class="iconfont icon-dayuhao1" @click="fanhui"></view>
			</view>
		</view>
		<view class="headtop clearfix" :style="{marginTop: pHeight + tHeight + 'px'}">
			<view class="left fl clearfix">
				<view class="mess fl" @click="qiehuan(1)">
					<view :class="[attrIndex==1?'active':'']">离线</view>
					<text class="dian" v-if="attrIndex == 1"></text>
				</view>
				<view class="mess mess1 fl" @click="qiehuan(2)">
					<view :class="[attrIndex==2?'active':'']">空仓</view>
					<text class="dian" v-if="attrIndex == 2"></text>
				</view>
				<view class="mess mess1 fl" @click="qiehuan(3)">
					<view :class="[attrIndex==3?'active':'']">满仓</view>
					<text class="dian" v-if="attrIndex == 3"></text>
				</view>
				<view class="mess mess1 fl" @click="qiehuan(4)">
					<view :class="[attrIndex==4?'active':'']">疑似坏宝</view>
					<text class="dian" v-if="attrIndex == 4"></text>
				</view>
				<view class="mess mess1 fl" @click="qiehuan(5)">
					<view :class="[attrIndex==5?'active':'']">设备休眠</view>
					<text class="dian" v-if="attrIndex == 5"></text>
				</view>
			</view>
			<!-- <view class="right fr clearfix" v-if="attrIndex == 1 || attrIndex == 2 || attrIndex == 3" @click="showstatus = true">
				<image :src="baseUrl + '/wximage/shaixuan.png'" class="fl"></image>
				<view class="name fl">筛选</view>
				<u-select v-model="showstatus" :list="timelist" @confirm="confirm"></u-select>
			</view>
			<view class="right fr clearfix" v-else>
				<image :src="baseUrl + '/wximage/shaixuanshang.png'" class="fl"></image>
				<image :src="baseUrl + '/wximage/shaixuanxia.png'" class="fl"></image>
				<view class="name fl">时间</view>
			</view> -->
		</view>
		<view class="headtishi" v-if="attrIndex == 4">
			<image :src="baseUrl + '/wximage/huaibao.png'"></image>
			<view class="tishi">疑似坏宝：连续三笔订单金额和实际金额为0,使用小于10分钟。</view>
		</view>
		<view class="headtishi headtishixm" v-if="attrIndex == 5">
			<image :src="baseUrl + '/wximage/xiumian.png'"></image>
			<view class="tishixm">设备休眠：连续三天无订单。</view>
		</view>
		<view class="nr" v-if="attrIndex == 1 || attrIndex == 2 || attrIndex == 3">
			<view class="empty" v-if="lxList.length == 0">
				<image :src="baseUrl + '/wximage/empty.png'"></image>
				<text>暂无相关数据</text>
			</view>
			<view class="list" v-else v-for="(item,index) in lxList" :key="index">
				<view class="liebiao clearfix">
					<view class="left fl">设备编号：</view>
					<view class="right fl">
						<view class="name" @click="topage('/subpackageA/equipment/weihu?deviceid='+ item.charger_number)">{{item.charger_number}}</view>
					</view>
				</view>
				<view class="liebiao clearfix">
					<view class="left fl">设备名称：</view>
					<view class="right fl">
						<view class="title">{{item.charger_name}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="item.charger_agents_id">
					<view class="left fl">所属代理商：</view>
					<view class="right fl">
						<view class="name" @click="topage('/subpackageA/agent/detail?id='+ item.charger_agents_id)">{{item.charger_agents_name}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="item.charger_bussiness_id">
					<view class="left fl">所属商户：</view>
					<view class="right fl">
						<view class="name" @click="topage('/subpackageA/business/detail?id='+ item.charger_bussiness_id)">{{item.charger_bussiness_name}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="item.charger_yuangong_id">
					<view class="left fl">负责员工：</view>
					<view class="right fl">
						<view class="name" @click="topage('/subpackageA/staff/detail?id='+ item.charger_yuangong_id)">{{item.charger_yuangong_name}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="item.charger_station_id">
					<view class="left fl">所属门店：</view>
					<view class="right fl">
						<view class="name" @click="topage('/subpackageA/store/detail?id='+ item.charger_station_id)">{{item.charger_station_name}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="attrIndex == 1">
					<view class="left fl">离线时间：</view>
					<view class="right fl">
						<view class="title">{{item.create_time}}</view>
					</view>
				</view>
				<view class="dingwei clearfix" v-if="attrIndex == 1">
					<image :src="baseUrl + '/wximage/lixian.png'"></image>
					<view class="name">离线超过{{item.xiaoshi}}小时{{item.fenzhong}}分钟</view>
				</view>
			</view>
		</view>
		<view class="nr nrts" v-if="attrIndex == 4">
			<view class="empty" v-if="lxList.length == 0">
				<image :src="baseUrl + '/wximage/empty.png'"></image>
				<text>暂无相关数据</text>
			</view>
			<view class="list" v-else v-for="(item,index) in lxList" :key="index">
				<view class="liebiao liebiaots clearfix">
					<view class="left fl">休眠天数：</view>
					<view class="right fl">
						<view class="title">已超过{{item.day}}天</view>
					</view>
				</view>
				<view class="liebiao clearfix">
					<view class="left fl">设备编号：</view>
					<view class="right fl">
						<view class="name" @click="topage('/subpackageA/equipment/weihu?deviceid='+ item.charger_number)">{{item.charger_number}}</view>
					</view>
				</view>
				<view class="liebiao clearfix">
					<view class="left fl">设备名称：</view>
					<view class="right fl">
						<view class="title">{{item.charger_name}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="item.charger_agents_id">
					<view class="left fl">所属代理商：</view>
					<view class="right fl">
						<view class="name" @click="topage('/subpackageA/agent/detail?id='+ item.charger_agents_id)">{{item.charger_agents_name}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="item.charger_bussiness_id">
					<view class="left fl">所属商户：</view>
					<view class="right fl">
						<view class="name" @click="topage('/subpackageA/business/detail?id='+ item.charger_bussiness_id)">{{item.charger_bussiness_name}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="item.charger_yuangong_id">
					<view class="left fl">负责员工：</view>
					<view class="right fl">
						<view class="name" @click="topage('/subpackageA/staff/detail?id='+ item.charger_yuangong_id)">{{item.charger_yuangong_name}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="item.charger_station_id">
					<view class="left fl">所属门店：</view>
					<view class="right fl">
						<view class="name" @click="topage('/subpackageA/store/detail?id='+ item.charger_station_id)">{{item.charger_station_name}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="nr nrts" v-if="attrIndex == 5">
			<view class="empty" v-if="lxList.length == 0">
				<image :src="baseUrl + '/wximage/empty.png'"></image>
				<text>暂无相关数据</text>
			</view>
			<view class="list" v-else v-for="(item,index) in lxList" :key="index">
				<view class="liebiao liebiaots clearfix">
					<view class="left fl">休眠天数：</view>
					<view class="right fl">
						<view class="title">已超过{{item.day}}天</view>
					</view>
				</view>
				<view class="liebiao clearfix">
					<view class="left fl">设备编号：</view>
					<view class="right fl">
						<view class="name" @click="topage('/subpackageA/equipment/weihu?deviceid='+ item.charger_number)">{{item.charger_number}}</view>
					</view>
				</view>
				<view class="liebiao clearfix">
					<view class="left fl">设备名称：</view>
					<view class="right fl">
						<view class="title">{{item.charger_name}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="item.charger_agents_id">
					<view class="left fl">所属代理商：</view>
					<view class="right fl">
						<view class="name" @click="topage('/subpackageA/agent/detail?id='+ item.charger_agents_id)">{{item.charger_agents_name}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="item.charger_bussiness_id">
					<view class="left fl">所属商户：</view>
					<view class="right fl">
						<view class="name" @click="topage('/subpackageA/business/detail?id='+ item.charger_bussiness_id)">{{item.charger_bussiness_name}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="item.charger_yuangong_id">
					<view class="left fl">负责员工：</view>
					<view class="right fl">
						<view class="name" @click="topage('/subpackageA/staff/detail?id='+ item.charger_yuangong_id)">{{item.charger_yuangong_name}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="item.charger_station_id">
					<view class="left fl">所属门店：</view>
					<view class="right fl">
						<view class="name" @click="topage('/subpackageA/store/detail?id='+ item.charger_station_id)">{{item.charger_station_name}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
				attrIndex: 1,
				showstatus: false,
				timelist: [{
					value: '0',
					label: '全部',
				}, {
					value: '1',
					label: '12小时',
				}, {
					value: '2',
					label: '24小时',
				}, {
					value: '3',
					label: '48小时以上',
				}],
				value: '',
				lxList: [],
				page: 1,
				pageSize: 10,
				total: 0,
			}
		},
		onLoad() {
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}
			
			this.getList(this.page,this.pageSize,this.attrIndex);
		},
		onReachBottom() {
			if (this.total != this.lxList.length) {
				this.page = this.page + 1;
					
				this.getList(this.page,this.pageSize,this.attrIndex);
			}
		},
		methods: {
			getList(page,pageSize,attrIndex){
				this.request({
					url: '/xcx/warnlist',
					data: {
						agent_id: uni.getStorageSync('agent_id'),
						role_id: uni.getStorageSync('role_id'),
						page: page,
						pageSize: pageSize,
						attr: attrIndex,
					},
					method: "POST"
				}).then(res => {
					if (res.data.code == 200) {
						this.total = res.data.data.total;
						this.lxList = this.lxList.concat(res.data.data.data);
					} else {
						uni.showToast({
							title: '请求失败，请稍后再试',
							icon: 'none'
						})
					}
				})
			},
			qiehuan(index){
				this.attrIndex = index;
				
				this.page = 1;
				this.pageSize = 10;
				this.total = 0;
				this.lxList = [];
				
				this.getList(this.page,this.pageSize,this.attrIndex);
			},
			confirm(e) {
				this.value = e[0].value;
			},
			topage(url){
				uni.navigateTo({
					url
				})
			},
			fanhui() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #f9f9ff;
	}
	
	.message {
		width: 100%;
		margin: 0 auto;
		
		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: left;
				color: #333333;
				font-size: 32rpx;
				padding-left: 74rpx;
				font-weight: 700;

				text {
					font-size: 24rpx;
				}

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 300rpx;
			padding: 10rpx 40rpx 0;
			box-sizing: border-box;

			.left {
				.mess {
					height: 48rpx;
					line-height: 48rpx;
					text-align: center;

					view {
						font-size: 24rpx;
						color: #333333;
					}

					.dian {
						width: 8rpx;
						height: 8rpx;
						background: #5C88FA;
						display: block;
						border-radius: 50%;
						margin: 0 auto;
					}

					.active {
						font-size: 32rpx;
						color: #333333;
						font-weight: 700;
						margin-left: 0;
					}
				}

				.mess1 {
					margin-left: 20rpx;
				}
			}

			.right {
				width: 116rpx;
				height: 36rpx;
				line-height: 36rpx;
				text-align: center;
				background: #FFFFFF;
				border-radius: 24rpx;
				margin-top: 6rpx;

				image {
					width: 36rpx;
					height: 36rpx;
					margin-left: 10rpx;
					margin-right: 6rpx;
				}

				.name {
					font-size: 24rpx;
					color: #333333;
				}
			}
		}
		
		.headtishi{
			width: 90%;
			margin: 0 auto;
			z-index: 70;
			margin-top: -210rpx;
			background: #FFFFFF;
			height: 40rpx;
			line-height: 40rpx;
			text-align: center;
			border-radius: 8rpx;
			position: relative;
			
			image{
				width: 40rpx;
				height: 46rpx;
				position: absolute;
				bottom: 6rpx;
				left: 8rpx;
			}
			
			.tishi{
				font-size: 20rpx;
				color: #FA5E5C;
			}
			
			.tishixm{
				font-size: 20rpx;
				color: #5C88FA;
			}
		}
		
		.headtishixm{
			text-align: left;
			padding-left: 58rpx;
		}
		
		.nr{
			width: 90%;
			margin: 0 auto;
			z-index: 70;
			margin-top: -210rpx;
			
			.list{
				width: 100%;
				background: #fff;
				border-radius: 20rpx;
				margin-bottom: 20rpx;
				padding: 40rpx 40rpx 10rpx;
				position: relative;
				
				.liebiao{
					margin-bottom: 30rpx;
					
					.left{
						font-size: 24rpx;
						color: #333333;
						width: 30%;
					}
					
					.right{
						
						.title{
							font-size: 24rpx;
							color: #333333;
						}
						
						.name{
							font-size: 24rpx;
							color: #5C88FA;
						}
					}
				}
				
				.dingwei{
					position: absolute;
					top: 0;
					right: 18rpx;
					height: 46rpx;
					line-height: 46rpx;
					
					image{
						width: 40rpx;
						height: 46rpx;
						float: left;
						margin-right: 6rpx;
					}
					
					.name{
						float: left;
						font-size: 24rpx;
						color: #FAA25C;
					}
				}
				
				.liebiaots{
					font-weight: 700;
				}
			}
		}
		
		.nrts{
			margin-top: 20rpx;
		}
		
		.empty{
			width: 100%;
			margin: 80rpx auto 0;
			text-align: center;
			
			image{
				width: 390rpx;
				height: 340rpx;
			}
			
			text{
				display: block;
				margin-top: 60rpx;
				font-size: 24rpx;
				color: #666666;
			}
		}
	}
</style>